//package com.guonl.controller;
//
//import com.github.rholder.retry.*;
//import com.guonl.exception.BusinessException;
//import com.guonl.model.ResponseResult;
//import com.guonl.service.GuavaRetryService;
//import lombok.extern.slf4j.Slf4j;
//import org.springframework.beans.factory.annotation.Autowired;
//import org.springframework.remoting.RemoteAccessException;
//import org.springframework.web.bind.annotation.GetMapping;
//import org.springframework.web.bind.annotation.RequestMapping;
//import org.springframework.web.bind.annotation.RestController;
//
//import java.util.concurrent.TimeUnit;
//
//
//@Slf4j
//@RestController
//@RequestMapping("/guava-retry")
//public class GuavaRetryController {
//
//    @Autowired
//    private GuavaRetryService guavaRetryService;
//
//
//    @GetMapping("/test")
//    public ResponseResult retryTest(Integer code) throws Exception {
//
////        test1(code);
//
//        test2(code);
//
//        return ResponseResult.ok("OK");
//    }
//
//    private void test1(Integer code) throws Exception {
//        // RetryerBuilder 构建重试实例 retryer,可以设置重试源且可以支持多个重试源，可以配置重试次数或重试超时时间，以及可以配置等待时间间隔
//        Retryer<Boolean> retryer = RetryerBuilder.<Boolean>newBuilder()
//                .retryIfExceptionOfType(RuntimeException.class)//设置异常重试源
//                .retryIfResult(res -> res == false)  //设置根据结果重试
//                .withWaitStrategy(WaitStrategies.fixedWait(3, TimeUnit.SECONDS)) //设置等待间隔时间
//                .withStopStrategy(StopStrategies.stopAfterAttempt(3)) //设置最大重试次数
//                .build();
//
//        try {
//            Boolean call = retryer.call(() -> guavaRetryService.retry(code));
//        } catch (Exception e) {
//            throw (Exception) e.getCause();
//        }
//    }
//
//    private ResponseResult test2(Integer code) throws Exception {
//        Retryer<ResponseResult> retryer = RetryerBuilder.<ResponseResult>newBuilder()
////                .retryIfExceptionOfType(RuntimeException.class)//设置异常重试源
//                .retryIfRuntimeException()
//                .retryIfResult(res -> {
//                    return res.getCode() != 0;
//                })  //设置根据结果重试
//                .withWaitStrategy(WaitStrategies.fixedWait(3, TimeUnit.SECONDS)) //设置等待间隔时间
//                .withStopStrategy(StopStrategies.stopAfterAttempt(3)) //设置最大重试次数
//                .build();
//
//        try {
//            ResponseResult call = retryer.call(() -> guavaRetryService.retry2(code));
//            return call;
//        } catch (Exception e) {
//            throw (Exception) e.getCause();
//        }
//    }
//
//
//}
